package math2;

/**
 * function represent a pulse with width 2dt on time domain
 * 
 * @author hbui
 * 
 */
public class PulseFunctionRToR extends FunctionRnToR {

	private double t;
	private double dt;
	private double y;

	/**
	 * 
	 * @param t
	 *            time point
	 * @param dt
	 *            half of width
	 * @param y
	 *            value
	 */
	public PulseFunctionRToR(double t, double dt, double y) {
		this.t = t;
		this.dt = dt;
		this.y = y;
	}

	@Override
	public double[] gradientAt(double... x) {
		return new double[] { 0.0 };
	}

	@Override
	public double valueAt(double... x) {
		if (Math.abs(x[0] - t) < dt) {
			return y;
		} else {
			return 0;
		}
	}

}
